package indi.kider.server.employee.service;

import indi.kider.common.model.employee.LeaveLog;
import indi.kider.server.employee.mapper.LeaveLogMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pers.vankid.common.utils.page.PageRequest;
import pers.vankid.common.utils.page.PageResponse;
import pers.vankid.common.utils.page.PageUtil;

import java.util.List;

/**
 * Created by shixj on 2018/4/26.
 */
@Slf4j
@Service
public class LeaveLogServiceImpl implements LeaveLogService {
    @Autowired
    private LeaveLogMapper leaveLogMapper;

    /**
     * 根据id获取
     *
     * @param id
     * @return
     */
    @Override
    public LeaveLog getLeaveLogById(Long id) {
        return leaveLogMapper.selectByPrimaryKey(id);
    }

    /**
     * 获取分页查询
     *
     * @param request
     * @return
     */
    @Override
    public PageResponse<List<LeaveLog>> getLeaveLogPages(PageRequest<LeaveLog> request) {
        PageUtil.start(request);
        return PageUtil.getPageResponse(leaveLogMapper.select(request.getQuery()));
    }

    /**
     * 不分页查询
     *
     * @param leaveLog
     * @return
     */
    @Override
    public List<LeaveLog> getLeaveLogs(LeaveLog leaveLog) {
        return leaveLogMapper.select(leaveLog);
    }

    /**
     * 新增
     *
     * @param leaveLog
     * @return
     */
    @Override
    public LeaveLog add(LeaveLog leaveLog) {
        if (leaveLog != null) {
            if (leaveLog.getId() == null || leaveLog.getId().equals(0L)) {
                leaveLog.setId(null);
                leaveLogMapper.insert(leaveLog);
            }
        }
        return leaveLog;
    }

    /**
     * 更新
     *
     * @param leaveLog
     * @return
     */
    @Override
    public LeaveLog modify(LeaveLog leaveLog) {
        if (leaveLog != null && leaveLog.getId() != null && leaveLog.getId() > 0L)
            leaveLogMapper.updateByPrimaryKeySelective(leaveLog);
        return leaveLog;
    }

    /**
     * 删除
     *
     * @param id
     */
    @Override
    public void delById(Long id) {
        leaveLogMapper.deleteByPrimaryKey(id);
    }
}
